import 'package:dio/dio.dart';
import 'package:gczn_hd/app/core/values/gczn_api.dart';
import 'package:gczn_hd/app/modules/login/model/login_model.dart';
import 'package:gczn_hd/app/modules/login/model/user_response.dart';

import '/app/core/base/base_remote_source.dart';
import '/app/core/model/github_search_query_param.dart';
import '/app/data/model/github_project_search_response.dart';
import '/app/data/remote/gczn_remote_data_source.dart';
import '/app/network/dio_provider.dart';

class GcznRemoteDataSourceImpl extends BaseRemoteSource implements GcznRemoteDataSource {

  @override
  Future<LoginResponse> login(LoginRequest data) {
    var dioCall = dioClient.post(GcznApi.login, data: data.toJson());
    try{
      return callApiWithErrorParser(dioCall).then((response){
        LoginResponse login = LoginResponse.fromJson(response.data["data"]);

        return login;
      });
    }catch(e){
      rethrow;
    }
  }

  @override
  Future<UserResponse> getUserMsg() {
    var dioCall = dioClient.get(GcznApi.getSignedUser);
    try{
      return callApiWithErrorParser(dioCall).then((response){
        UserResponse data = UserResponse.fromJson(response.data["data"]);

        return data;
      });

    }catch(e){
      rethrow;
    }
  }

  @override
  Future<bool> logout() {
    var dioCall = dioClient.post(GcznApi.logout);

    try{
      return callApiWithErrorParser(dioCall).then((response){
        return true;
      });

    }catch(e){
      rethrow;
    }
  }
}
